package com.web;

import com.domain.actPlan;
import com.service.userService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 用户完善活动的数据,将actPlan表进行完善，完善打分和反馈
 * 接收 userSelfAct.jsp 页面的userId、activityId 数据
 * 提交到 userService 的 findUserAct 函数
 * 转发到 updateAPASelf.jsp 页面进行展示
 */
@WebServlet("/findUserActSelf")
public class findUserActSelfServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //解决乱码
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");

        //1.接受有传入的参数
        String userId = request.getParameter("userId");
        String activityId = request.getParameter("activityId");

        //2.调用service层的,查询
        actPlan actplan = new userService().findUserAct(Integer.parseInt(userId), Integer.parseInt(activityId));
        System.out.println("查询了 userId="+userId+" activityId="+ activityId+" 的用户活动");

        //3.判断对象存不存在
        if(actplan != null){
            //4.1对象存在展示
            request.setAttribute("actPlan", actplan);
            //4.2转发到update.jsp进行展示
            request.getRequestDispatcher("/updateAPASelf.jsp").forward(request,response);

        }else{
            //5.对象不存在,重定向到查询客户
            response.sendRedirect(request.getContextPath()+"/ShowUserSelf?userId="+userId);
        }


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
